<template>
  <!--新增按钮的弹框  -->
  <div>
    <FormVue ref="form" v-loading="loadingAdd" :form-data="dialogForm" :form="dialogFormData"  class="formMain" />
    <span slot="footer" class="dialog-footer">
      <el-button size="small" @click="cancel()">取 消</el-button>
      <el-button type="primary" size="small" @click="handleDialogConfirm()">确认</el-button>
    </span>
  </div>
</template>

<script>
import FormVue from "@/components/common/FormVue";

export default {
  name: "NewDialog",
  components: { FormVue },
  props: {
    visible: { type: Boolean, required: true },
    edit: { type: Boolean, required: true },
    dialogForm: { type: Object, default: {} },
    dialogFormData: {
      type: Object,
      // eslint-disable-next-line vue/require-valid-default-prop
      default: {},
    },
  },
  data() {
    return {
      dialogVisible: this.visible,
      isEdit: this.edit,
      loadingAdd: false,
      form: this.dialogForm,
      formData: this.dialogFormData,
    };
  },
  created() {},
  methods: {
    // 对话框按确定键之后的方法
    handleDialogConfirm() {
      if (this.isEdit) {
        // 更新资源数据（即编辑修改）
        this.dialogVisible = false;
          this.$emit("update",);
          // this.$parent.$parent.update();
        //回调刷新列表（重新拉一次数据）
      } else {
        // 插入一条资源数据（即添加）
        //注意父组件的 父组件
        //  this.$parent.$parent.add();
            this.$emit("add",);
        this.dialogVisible = false;
      }
    },
    // 按取消键后
    cancel() {
      this.$emit("close",);
      this.$emit("update:visible", false);
    },
  },
};
</script>

<style scoped>
/* .formMain {
  height: 1000px;
} */
.dialog-footer {
  display: flex;
  justify-content: center;
  /*height: 30px;*/
}
</style>